﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using CoiffeurProject.Screens;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Input;
using CoiffeurProject.Utils;
using System.Windows.Media;

namespace CoiffeurProject.UserControls
{
    internal class CustCheckBox
    {
        Grid main_container;
        Image checked_box, not_checked_box;
        Button button;
        bool isChecked;

        internal CustCheckBox(Thickness margin, int col, int row, bool isChecked)
        {
            this.isChecked = isChecked;

            main_container = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                Width = 22,
                Height = 23,
                Margin = margin
            };

            Grid.SetColumn(main_container, col);
            Grid.SetRow(main_container, row);

            checked_box = new Image() { Source = new BitmapImage(new Uri(ImagesPath.CheckBox)), Stretch = Stretch.Fill };
            not_checked_box = new Image() { Source = new BitmapImage(new Uri(ImagesPath.EmptyCheckBox)), Stretch = Stretch.Fill };            

            button = new Button()
            {
                Width = 22,
                Height = 23,
                Content = isChecked ? checked_box : not_checked_box
            };

            button.SetResourceReference(Button.StyleProperty, "NoChromeButton");
            button.Click += new RoutedEventHandler(button_Click);

            main_container.Children.Add(button);
        }

        void button_Click(object sender, RoutedEventArgs e)
        {
            if (!isChecked)
            {
                isChecked = !isChecked;
                button.Content = isChecked ? checked_box : not_checked_box;
            }
        }

        public void AddClickEventHandler(Action<object, RoutedEventArgs> action)
        {
            button.Click += new RoutedEventHandler(action);
        }

        public void ToggleCheck()
        {
            if (isChecked)
            {
                isChecked = !isChecked;
                button.Content = isChecked ? checked_box : not_checked_box;
            }
        }

        public void Activate()
        {
            isChecked = true;
            button.Content = checked_box;
        }

        public void Deactivate()
        {
            isChecked = false;
            button.Content = not_checked_box;
        }

        public bool IsChecked
        {
            get { return isChecked; }
        }

        public Grid MainContainer
        {
            get { return main_container; }
        }
    }
}
